﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OleDb;
using Oracle.DataAccess.Client;
using System.Threading;
using System.Text;
using StudentManage.Data;
using StudentManage.Common;

namespace StudentManage.Web.Admin.Management.SysManage
{
    public partial class DataSynOracle : SecurityPage
    {
        public override string PrivCode()
        {
            return "e56cd197be997e51";
        }

        private static DataTable dt_Add = new DataTable();
        private static DataTable dt_Up = new DataTable();
        private static List<string> Idlist = new List<string>();

        public bool IsSame(DataRow newrow, DataRow oldrow, DataColumnCollection columns, string NoField)
        {
            bool b = true;
            foreach (DataColumn item in columns)
            {
                if (!newrow.Table.Columns.Contains(item.ColumnName)) continue;

                if (NoField != "" && item.ColumnName == NoField) continue;

                if (oldrow[item.ColumnName].ToString() != newrow[item.ColumnName].ToString())
                {
                    b = false;
                    break;
                }
            }
            return b;
        }

        public DataTable GetOraceldt(string sqlstr)
        {
            DataTable dt = new DataTable();
            OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["StudentManageMentOracle"].ToString());
            OracleDataAdapter oap = new OracleDataAdapter(sqlstr, con);
            con.Open();
            oap.Fill(dt);
            con.Close();
            return dt;
        }

        public DataTable GetSqldt(string sqlstr)
        {
            DataTable dt = new DataTable();
            SqlConnection consql = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentManageMentConnectionString"].ToString());
            consql.Open();
            SqlDataAdapter sap = new SqlDataAdapter(sqlstr, consql);
            sap.Fill(dt);
            consql.Close();
            return dt;
        }

        public int GetMaxId()
        {
            SqlConnection consql = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentManageMentConnectionString"].ToString());
            consql.Open();
            SqlCommand com = new SqlCommand("select MAX(id) from UserList", consql);
            object o = com.ExecuteScalar();
            consql.Close();
            return o.ToString() == "" ? 1 : Convert.ToInt32(o)+1;
        }

        public void ExecSqlstr(string sql)
        {
            SqlConnection consql = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentManageMentConnectionString"].ToString());
            consql.Open();
            SqlCommand com = new SqlCommand(sql, consql);
            com.ExecuteNonQuery();
            consql.Close();
        }

        private string GetSqlstr(string TableName, string KeyColumn, DataColumnCollection columns, DataRow row,DataColumnCollection oldcolumns,string NoField)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("update " + TableName + " set ");
            StringBuilder sb_item = new StringBuilder();
            foreach (DataColumn item in columns)
            {
                if (!oldcolumns.Contains(item.ColumnName)) continue;

                if (item.ColumnName != KeyColumn && item.ColumnName != NoField)
                {
                    if (item.DataType.Name == "String")
                    {
                        sb_item.Append(item.ColumnName + "='" + row[item.ColumnName].ToString() + "',");
                    }
                    else if (item.DataType.Name == "Int64" || item.DataType.Name == "Int32" || item.DataType.Name == "Int16")
                    {
                        if (row[item.ColumnName].ToString() != "")
                        {
                            sb_item.Append(item.ColumnName + "=" + row[item.ColumnName].ToString() + ",");
                        }
                        else
                        {
                            sb_item.Append(item.ColumnName + "=null,");
                        }
                    }
                }
            }
            sb.Append(sb_item.ToString().TrimEnd(','));
            sb.Append("where " + KeyColumn + "='" + row[KeyColumn].ToString() + "'");
            return sb.ToString();
        }

        //使用SqlBulkCopy方式插入数据
        public void SqlBulkCopyInsert(DataTable insertdt, string TableName)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["StudentManageMentConnectionString"].ToString();
            DataTable dataTable = insertdt;
            SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(connectionString);
            sqlBulkCopy.DestinationTableName = TableName;//设置需要插入数据表名
            sqlBulkCopy.BatchSize = dataTable.Rows.Count;//设置批量插入数据的最大数据量的值
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            if (dataTable != null && dataTable.Rows.Count != 0)
            {
                sqlBulkCopy.WriteToServer(dataTable);
            }
            sqlBulkCopy.Close();
            sqlConnection.Close();
        }

        //获取数据
        private void GetData(string TableName,string KeyCloumnName,string NoBJColumn="")
        {
            dt_Add = new DataTable();
            dt_Up = new DataTable();
            Idlist = new List<string>();
            DataTable dt_new = GetOraceldt("select * from " + TableName);
            DataTable dt_old = GetSqldt("select * from " + TableName);

            dt_Add = dt_new.Clone();
            dt_Up = dt_new.Clone();
            for (int i = 0; i < dt_new.Rows.Count; i++)
            {
                DataRow[] oldrow = dt_old.Select(KeyCloumnName + "='" + dt_new.Rows[i][KeyCloumnName].ToString() + "'");
                if (oldrow.Count() < 1)
                {
                    DataRow row = dt_Add.NewRow();
                    row.ItemArray = dt_new.Rows[i].ItemArray;
                    dt_Add.Rows.Add(row);
                }
                else
                {
                    if (NoBJColumn != "")
                    {
                        if (oldrow[0]["IsEdit"] is DBNull || !Convert.ToBoolean(oldrow[0]["IsEdit"]))
                        {
                            NoBJColumn = "";
                        }
                        else
                        {
                            Idlist.Add(oldrow[0][KeyCloumnName].ToString());
                        }
                    }

                    if (!this.IsSame(dt_new.Rows[i], oldrow[0], dt_old.Columns, NoBJColumn))
                    {
                        DataRow row = dt_Up.NewRow();
                        row.ItemArray = dt_new.Rows[i].ItemArray;
                        dt_Up.Rows.Add(row);
                    }
                }
            }
        }

        //修改数据
        private void UpdateData(string TableName, string KeyCloumnName,string NoBJColumn="")
        {
            SqlConnection consql = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentManageMentConnectionString"].ToString());
            consql.Open();
            DataTable dt_old = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter("select top 1 * from "+TableName,consql);
            sda.Fill(dt_old);
            for (int i = 0; i < dt_Up.Rows.Count; i++)
            {
                if (NoBJColumn != "")
                {
                    if (!Idlist.Contains(KeyCloumnName))
                    {
                        NoBJColumn = "";
                    }
                }

                string sqlstr = this.GetSqlstr(TableName, KeyCloumnName, dt_Up.Columns, dt_Up.Rows[i], dt_old.Columns,NoBJColumn);
                SqlCommand com = new SqlCommand(sqlstr, consql);
                com.ExecuteNonQuery();
            }
            consql.Close();
        }

        //禁用控件
        private void BtnEnabled(string BtnName)
        {
            this.Btn_ExecUpLoadXQ.Enabled = (BtnName == "XQ");
            this.Btn_ExecUpLoadXY.Enabled = (BtnName == "XY");
            this.Btn_ExecUpLoadBM.Enabled = (BtnName == "BM");
            this.Btn_ExecUpLoadBJ.Enabled = (BtnName == "BJ");
            this.Btn_ExecUpLoadJG.Enabled = (BtnName == "JG");
            this.Btn_ExecUpLoadXS.Enabled = (BtnName == "XS");
        }

        //清空状态提醒
        private void ClearStatus()
        {
            this.lab_XQ_status.Text = "";
            this.lab_XY_status.Text = "";
            this.lab_BM_status.Text = "";
            this.lab_BJ_status.Text = "";
            this.lab_JG_status.Text = "";
            this.lab_XS_status.Text = "";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
        }

        //校区
        protected void Btn_UpLoadXQ_Click(object sender, EventArgs e)
        {
            this.GetData("xqdm", "XQDM");
            this.lab_XQ_InCount.Text = (dt_Add != null ? dt_Add.Rows.Count.ToString() : "0");
            this.lab_XQ_UpCount.Text = (dt_Up != null ? dt_Up.Rows.Count.ToString() : "0");
            this.BtnEnabled("XQ");
        }
        protected void Btn_ExecUpLoadXQ_Click(object sender, EventArgs e)
        {
            this.Btn_ExecUpLoadXQ.Enabled = false;

            DataTable dt = new DataTable();
            dt.Columns.Add("XQDM", typeof(string));
            dt.Columns.Add("XQMC", typeof(string));
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["XQDM"] = dt_Add.Rows[i]["XQDM"].ToString();
                row["XQMC"] = dt_Add.Rows[i]["XQMC"].ToString();
                dt.Rows.Add(row);
            }
            this.SqlBulkCopyInsert(dt, "xqdm");
            this.UpdateData("xqdm", "XQDM");

            this.lab_XQ_status.Text = "执行完毕!";
            this.lab_XQ_InCount.Text = "";
            this.lab_XQ_UpCount.Text = "";
        }

        //学院
        protected void Btn_UpLoadXY_Click(object sender, EventArgs e)
        {
            this.GetData("xydm", "XYDM");
            this.lab_XY_InCount.Text = (dt_Add != null ? dt_Add.Rows.Count.ToString() : "0");
            this.lab_XY_UpCount.Text = (dt_Up != null ? dt_Up.Rows.Count.ToString() : "0");
            this.BtnEnabled("XY");
        }
        protected void Btn_ExecUpLoadXY_Click(object sender, EventArgs e)
        {
            this.Btn_ExecUpLoadXY.Enabled = false;

            DataTable dt = new DataTable();
            dt.Columns.Add("XYDM", typeof(string));
            dt.Columns.Add("XYMC", typeof(string));
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["XYDM"] = dt_Add.Rows[i]["XYDM"].ToString();
                row["XYMC"] = dt_Add.Rows[i]["XYMC"].ToString();
                dt.Rows.Add(row);
            }
            this.SqlBulkCopyInsert(dt, "xydm");
            this.UpdateData("xydm", "XYDM");
            
            this.lab_XY_status.Text = "执行完毕!";
            this.lab_XY_InCount.Text = "";
            this.lab_XY_UpCount.Text = "";
        }

        //部门
        protected void Btn_UpLoadBM_Click(object sender, EventArgs e)
        {
            this.GetData("xy_bmxbm", "BMDM");
            this.lab_BM_InCount.Text = (dt_Add != null ? dt_Add.Rows.Count.ToString() : "0");
            this.lab_BM_UpCount.Text = (dt_Up != null ? dt_Up.Rows.Count.ToString() : "0");
            this.BtnEnabled("BM");
        }
        protected void Btn_ExecUpLoadBM_Click(object sender, EventArgs e)
        {
            this.Btn_ExecUpLoadBM.Enabled = false;

            DataTable dt = new DataTable();
            dt.Columns.Add("BMDM", typeof(string));
            dt.Columns.Add("BMMC", typeof(string));
            dt.Columns.Add("BMFQID", typeof(string));
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["BMDM"] = dt_Add.Rows[i]["BMDM"].ToString();
                row["BMMC"] = dt_Add.Rows[i]["BMMC"].ToString();
                row["BMFQID"] = dt_Add.Rows[i]["BMFQID"].ToString();
                dt.Rows.Add(row);
            }
            this.SqlBulkCopyInsert(dt, "xy_bmxbm");
            this.UpdateData("xy_bmxbm", "BMDM");

            this.lab_BM_status.Text = "执行完毕!";
            this.lab_BM_InCount.Text = "";
            this.lab_BM_UpCount.Text = "";
        }

        //班级
        protected void Btn_UpLoadBJ_Click(object sender, EventArgs e)
        {
            this.GetData("xy_bj", "BJDM");
            this.lab_BJ_InCount.Text = (dt_Add != null ? dt_Add.Rows.Count.ToString() : "0");
            this.lab_BJ_UpCount.Text = (dt_Up != null ? dt_Up.Rows.Count.ToString() : "0");
            this.BtnEnabled("BJ");
        }
        protected void Btn_ExecUpLoadBJ_Click(object sender, EventArgs e)
        {
            this.Btn_ExecUpLoadBJ.Enabled = false;

            DataTable dt = new DataTable();
            dt.Columns.Add("BJMC", typeof(string));
            dt.Columns.Add("BJDM", typeof(string));
            dt.Columns.Add("XYMC", typeof(string));
            dt.Columns.Add("XYDM", typeof(string));
            dt.Columns.Add("NJ", typeof(string));
            dt.Columns.Add("SSZYDM", typeof(string));
            dt.Columns.Add("SSZYMC", typeof(string));
            dt.Columns.Add("XZ", typeof(string));
            dt.Columns.Add("CC", typeof(string));
            dt.Columns.Add("SFBY", typeof(string));
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["BJMC"] = dt_Add.Rows[i]["BJMC"].ToString();
                row["BJDM"] = dt_Add.Rows[i]["BJDM"].ToString();
                row["XYMC"] = dt_Add.Rows[i]["XYMC"].ToString();
                row["XYDM"] = dt_Add.Rows[i]["XYDM"].ToString();
                row["NJ"] = dt_Add.Rows[i]["NJ"].ToString();
                row["SSZYDM"] = dt_Add.Rows[i]["SSZYDM"].ToString();
                row["SSZYMC"] = dt_Add.Rows[i]["SSZYMC"].ToString();
                row["XZ"] = dt_Add.Rows[i]["XZ"].ToString();
                row["CC"] = dt_Add.Rows[i]["CC"].ToString();
                row["SFBY"] = dt_Add.Rows[i]["SFBY"].ToString();
                dt.Rows.Add(row);
            }
            this.SqlBulkCopyInsert(dt, "xy_bj");
            this.UpdateData("xy_bj", "BJDM");

            this.lab_BJ_status.Text = "执行完毕!";
            this.lab_BJ_InCount.Text = "";
            this.lab_BJ_UpCount.Text = "";
        }

        //教工
        protected void Btn_UpLoadJG_Click(object sender, EventArgs e)
        {
            this.GetData("xy_jgxx", "ZGH", "BMDM");
            this.lab_JG_InCount.Text = (dt_Add != null ? dt_Add.Rows.Count.ToString() : "0");
            this.lab_JG_UpCount.Text = (dt_Up != null ? dt_Up.Rows.Count.ToString() : "0");
            this.BtnEnabled("JG");
        }
        protected void Btn_ExecUpLoadJG_Click(object sender, EventArgs e)
        {
            this.Btn_ExecUpLoadJG.Enabled = false;

            #region 用户表
            DataTable dt_user = new DataTable();
            dt_user.Columns.Add("id", typeof(int));
            dt_user.Columns.Add("XH", typeof(string));
            dt_user.Columns.Add("IsStudent", typeof(bool));
            dt_user.Columns.Add("UserName", typeof(string));
            dt_user.Columns.Add("PassWord", typeof(string));
            dt_user.Columns.Add("UName", typeof(string));
            dt_user.Columns.Add("Tel", typeof(string));
            dt_user.Columns.Add("QQ", typeof(string));
            dt_user.Columns.Add("Email", typeof(string));
            dt_user.Columns.Add("Specialty", typeof(string));
            dt_user.Columns.Add("Experience", typeof(string));
            dt_user.Columns.Add("Hobby", typeof(string));
            dt_user.Columns.Add("DataRole", typeof(int));
            dt_user.Columns.Add("RoleCode", typeof(string));
            dt_user.Columns.Add("RoleName", typeof(string));
            dt_user.Columns.Add("AddTime", typeof(DateTime));

            int MaxId = this.GetMaxId();
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt_user.NewRow();
                row["id"] = MaxId;
                row["XH"] = dt_Add.Rows[i]["ZGH"].ToString();
                row["IsStudent"] = false;
                row["UserName"] = dt_Add.Rows[i]["ZGH"].ToString();
                row["PassWord"] = Utility.GetMD5PassWord(dt_Add.Rows[i]["ZGH"].ToString(), "");
                row["UName"] = dt_Add.Rows[i]["XM"].ToString();
                row["Tel"] = "";
                row["QQ"] = "";
                row["Email"] = "";
                row["Specialty"] = "";
                row["Experience"] = "";
                row["Hobby"] = "";
                row["DataRole"] = 12;//部门管理员
                row["RoleCode"] = "463915fcee193102";
                row["RoleName"] = "部门管理员";
                row["AddTime"] = DateTime.Now;
                dt_user.Rows.Add(row);
                MaxId += 1;
            }
            #endregion

            #region 教工表
            DataTable dt = new DataTable();
            dt.Columns.Add("ZGH", typeof(string));
            dt.Columns.Add("XM", typeof(string));
            dt.Columns.Add("XB", typeof(string));
            dt.Columns.Add("XYMC", typeof(string));
            dt.Columns.Add("BMMC", typeof(string));
            dt.Columns.Add("BMDM", typeof(string));
            dt.Columns.Add("CARDID", typeof(int));
            dt.Columns.Add("RYLB", typeof(string));
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["ZGH"] = dt_Add.Rows[i]["ZGH"].ToString();
                row["XM"] = dt_Add.Rows[i]["XM"].ToString();
                row["XB"] = dt_Add.Rows[i]["XB"].ToString();
                row["XYMC"] = dt_Add.Rows[i]["XYMC"].ToString();
                row["BMMC"] = dt_Add.Rows[i]["BMMC"].ToString();
                row["BMDM"] = dt_Add.Rows[i]["BMDM"].ToString();
                if (dt_Add.Rows[i]["CARDID"] != null && dt_Add.Rows[i]["CARDID"].ToString() != "")
                {
                    row["CARDID"] = Convert.ToInt32(dt_Add.Rows[i]["CARDID"].ToString());
                }
                row["RYLB"] = dt_Add.Rows[i]["RYLB"].ToString();
                dt.Rows.Add(row);
            }
            #endregion

            this.ExecSqlstr("set IDENTITY_INSERT UserList on");
            this.SqlBulkCopyInsert(dt_user, "UserList");
            this.ExecSqlstr("set IDENTITY_INSERT UserList OFF");

            this.SqlBulkCopyInsert(dt, "xy_jgxx");
            this.UpdateData("xy_jgxx", "ZGH", "BMDM");

            this.lab_JG_status.Text = "执行完毕!";
            this.lab_JG_InCount.Text = "";
            this.lab_JG_UpCount.Text = "";
        }

        //学生
        protected void Btn_UpLoadXS_Click(object sender, EventArgs e)
        {
            this.GetData("xy_xsxx", "XH", "BJDM");
            this.lab_XS_InCount.Text = (dt_Add != null ? dt_Add.Rows.Count.ToString() : "0");
            this.lab_XS_UpCount.Text = (dt_Up != null ? dt_Up.Rows.Count.ToString() : "0");
            this.BtnEnabled("XS");
        }
        protected void Btn_ExecUpLoadXS_Click(object sender, EventArgs e)
        {
            this.Btn_ExecUpLoadXS.Enabled = false;

            #region 用户表
            DataTable dt_user = new DataTable();
            dt_user.Columns.Add("id", typeof(int));
            dt_user.Columns.Add("XH", typeof(string));
            dt_user.Columns.Add("IsStudent", typeof(bool));
            dt_user.Columns.Add("UserName", typeof(string));
            dt_user.Columns.Add("PassWord", typeof(string));
            dt_user.Columns.Add("UName", typeof(string));
            dt_user.Columns.Add("Tel", typeof(string));
            dt_user.Columns.Add("QQ", typeof(string));
            dt_user.Columns.Add("Email", typeof(string));
            dt_user.Columns.Add("Specialty", typeof(string));
            dt_user.Columns.Add("Experience", typeof(string));
            dt_user.Columns.Add("Hobby", typeof(string));
            dt_user.Columns.Add("DataRole", typeof(int));
            dt_user.Columns.Add("RoleCode", typeof(string));
            dt_user.Columns.Add("RoleName", typeof(string));
            dt_user.Columns.Add("AddTime", typeof(DateTime));

            int MaxId = this.GetMaxId();
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt_user.NewRow();
                row["id"] = MaxId;
                row["XH"] = dt_Add.Rows[i]["XH"].ToString();
                row["IsStudent"] = true;
                row["UserName"] = dt_Add.Rows[i]["XH"].ToString();
                row["PassWord"] = Utility.GetMD5PassWord(dt_Add.Rows[i]["XH"].ToString(),"");
                row["UName"] = dt_Add.Rows[i]["XM"].ToString();
                row["Tel"] = "";
                row["QQ"] = "";
                row["Email"] = "";
                row["Specialty"] = "";
                row["Experience"] = "";
                row["Hobby"] = "";
                row["DataRole"] = 13;//学生管理员
                row["RoleCode"] = "2e8ad540e9889cfb";
                row["RoleName"] = "学生";
                row["AddTime"] = DateTime.Now;
                dt_user.Rows.Add(row);
                MaxId += 1;
            }
            #endregion

            #region 学生表
            DataTable dt = new DataTable();
            dt.Columns.Add("XH", typeof(string));
            dt.Columns.Add("XM", typeof(string));
            dt.Columns.Add("XB", typeof(string));
            dt.Columns.Add("ZYMC", typeof(string));
            dt.Columns.Add("ZYDM", typeof(string));
            dt.Columns.Add("XZB", typeof(string));
            dt.Columns.Add("BJDM", typeof(string));
            dt.Columns.Add("XY", typeof(string));
            dt.Columns.Add("XYDM", typeof(string));
            dt.Columns.Add("NJ", typeof(int));
            dt.Columns.Add("XZ", typeof(string));
            dt.Columns.Add("XL", typeof(string));
            dt.Columns.Add("XJZT", typeof(string));
            dt.Columns.Add("CARDID", typeof(int));
            dt.Columns.Add("YDLB", typeof(string));
            
            for (int i = 0; i < dt_Add.Rows.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["XH"] = dt_Add.Rows[i]["XH"].ToString();
                row["XM"] = dt_Add.Rows[i]["XM"].ToString();
                row["XB"] = dt_Add.Rows[i]["XB"].ToString();
                row["ZYMC"] = dt_Add.Rows[i]["ZYMC"].ToString();
                row["ZYDM"] = dt_Add.Rows[i]["ZYDM"].ToString();
                row["XZB"] = dt_Add.Rows[i]["XZB"].ToString();
                row["BJDM"] = dt_Add.Rows[i]["BJDM"].ToString();
                row["XY"] = dt_Add.Rows[i]["XY"].ToString();
                row["XYDM"] = dt_Add.Rows[i]["XYDM"].ToString();
                if (dt_Add.Rows[i]["NJ"] != null && dt_Add.Rows[i]["NJ"].ToString() != "")
                {
                    row["NJ"] = Convert.ToInt32(dt_Add.Rows[i]["NJ"].ToString());
                }
                row["XZ"] = dt_Add.Rows[i]["XZ"].ToString();
                row["XL"] = dt_Add.Rows[i]["XL"].ToString();
                row["XJZT"] = dt_Add.Rows[i]["XJZT"].ToString();
                if (dt_Add.Rows[i]["CARDID"] != null && dt_Add.Rows[i]["CARDID"].ToString() != "")
                {
                    row["CARDID"] = Convert.ToInt32(dt_Add.Rows[i]["CARDID"].ToString());
                }
                row["YDLB"] = dt_Add.Rows[i]["YDLB"].ToString();
                dt.Rows.Add(row);
            }
            #endregion

            this.ExecSqlstr("set IDENTITY_INSERT UserList on");
            this.SqlBulkCopyInsert(dt_user, "UserList");
            this.ExecSqlstr("set IDENTITY_INSERT UserList OFF");

            this.SqlBulkCopyInsert(dt, "xy_xsxx");
            this.UpdateData("xy_xsxx", "XH", "BJDM");

            this.lab_XS_status.Text = "执行完毕!";
            this.lab_XS_InCount.Text = "";
            this.lab_XS_UpCount.Text = "";
        }

    }
}